/**
 * 
 */
package com.module.bp.player;

import com.dalonedrau.d20.Diceroller;
import com.dalonedrau.jogl.engine.GameApplet;
import com.rpg.base.Player;
import com.rpg.base.interactive.flyweight.BaseInteractiveObject;

/**
 * Completed:<br>
 *  - R201 - defined character abilities in BPConsts
 *  - R202 - defined in Prince
 * <br>
 * To Be Done:<br>
 * - everything<br>
 * 
 * @author Donald
 *
 */
public class BPPlayer implements Player<BPCharacter> {
	/** the singleton instance of {@link BPPlayer}. */
	private static BPPlayer	instance;
	/**
	 * Gets the singleton instance of {@link BPPlayer}.
	 * @return {@link BPPlayer}
	 */
	public static BPPlayer getInstance() {
		if (BPPlayer.instance == null) {
			BPPlayer.instance = new BPPlayer();
		}
		return BPPlayer.instance;
	}
	/** Hidden constructor. */
	private BPPlayer() {}
	public long getWealth(final int code) {
		long g = 0;
		int roll = Diceroller.getInstance().rolldX(BPConsts.DIE_ROLL);
		switch (code) {
		case 0: break;
		case 1: 
			switch (roll) {
			case 3:
			case 4:
				g = 1;
				break;
			case 5:
			case 6:
				g = 2;
				break;
				default: break;
			}
			break;
		case 2: 
			switch (roll) {
			case 2:
				g = 2;
				break;
			case 3:
			case 4:
				g = 2;
				break;
			case 5:
				g = 3;
				break;
			case 6:
				g = 4;
				break;
				default: break;
			}
			break;
		case 4: 
			switch (roll) {
			case 1:
				g = 2;
				break;
			case 2:
				g = 3;
				break;
			case 3:
			case 4:
				g = 4;
				break;
			case 5:
				g = 5;
				break;
			default: // 6
				g = 6;
				break;
			}
			break;
		case 5:
			switch (roll) {
			case 1:
				g = 2;
				break;
			case 2:
				g = 3;
				getWealth((int) 'A');
				break;
			case 3:
				g = 4;
				break;
			case 4:
				g = 6;
				getWealth((int) 'A');
				break;
			case 5:
				g = 6;
				break;
			default: // 6
				g = 8;
				getWealth((int) 'A');
				break;
			}
			break;
		case 7: 
			switch (roll) {
			case 1:
				g = 3;
				break;
			case 2:
				g = 4;
				break;
			case 3:
				g = 6;
				break;
			case 4:
				g = 8;
				break;
			case 5:
				g = 10;
				break;
			default: // 6
				g = 11;
				break;
			}
			break;
		case 10: 
			switch (roll) {
			case 1:
				g = 6;
				break;
			case 2:
				g = 8;
				break;
			case 3:
				g = 9;
				break;
			case 4:
				g = 11;
				break;
			case 5:
				g = 12;
				break;
			default: // 6
				g = 14;
				break;
			}
			break;
		case 12: 
			switch (roll) {
			case 1:
				g = 5;
				break;
			case 2:
				g = 9;
				getWealth((int) 'C');
				break;
			case 3:
				g = 11;
				getWealth((int) 'A');
				break;
			case 4:
				g = 12;
				break;
			case 5:
				g = 15;
				getWealth((int) 'A');
				break;
			default: // 6
				g = 20;
				break;
			}
			break;
		case 15: 
			switch (roll) {
			case 1:
				g = 10;
				break;
			case 2:
				g = 12;
				break;
			case 3:
				g = 14;
				break;
			case 4:
				g = 16;
				break;
			case 5:
				g = 18;
				break;
			default: // 6
				g = 20;
				break;
			}
			break;
		case 21: 
			switch (roll) {
			case 1:
				g = 15;
				break;
			case 2:
				g = 18;
				break;
			case 3:
				g = 20;
				break;
			case 4:
				g = 22;
				break;
			case 5:
				g = 24;
				break;
			default: // 6
				g = 27;
				break;
			}
			break;
		case 25: 
			switch (roll) {
			case 1:
				g = 20;
				getWealth((int) 'A');
				break;
			case 2:
				g = 22;
				break;
			case 3:
				g = 24;
				getWealth((int) 'A');
				break;
			case 4:
				g = 26;
				break;
			case 5:
				g = 28;
				getWealth((int) 'A');
				break;
			default: // 6
				g = 30;
				break;
			}
			break;
		case 30: 
			switch (roll) {
			case 1:
				g = 23;
				break;
			case 2:
				g = 27;
				break;
			case 3:
				g = 29;
				break;
			case 4:
				g = 31;
				break;
			case 5:
				g = 33;
				break;
			default: // 6
				g = 37;
				break;
			}
			break;
		case 50: 
			switch (roll) {
			case 1:
				g = 40;
				break;
			case 2:
				g = 45;
				break;
			case 3:
				g = 48;
				break;
			case 4:
				g = 52;
				break;
			case 5:
				g = 55;
				break;
			default: // 6
				g = 60;
				break;
			}
			break;
		case 60: 
			switch (roll) {
			case 1:
				g = 45;
				getWealth((int) 'A');
				break;
			case 2:
				g = 50;
				getWealth((int) 'C');
				break;
			case 3:
				g = 55;
				break;
			case 4:
				g = 60;
				getWealth((int) 'B');
				break;
			case 5:
				g = 70;
				getWealth((int) 'A');
				break;
			default: // 6
				g = 80;
				break;
			}
			break;
		case 70: 
			switch (roll) {
			case 1:
				g = 55;
				break;
			case 2:
				g = 60;
				break;
			case 3:
				g = 65;
				break;
			case 4:
				g = 70;
				break;
			case 5:
				g = 80;
				break;
			default: // 6
				g = 90;
				break;
			}
			break;
		case 100: 
			switch (roll) {
			case 1:
				g = 85;
				break;
			case 2:
				g = 90;
				break;
			case 3:
				g = 95;
				break;
			case 4:
				g = 100;
				break;
			case 5:
				g = 110;
				break;
			default: // 6
				g = 120;
				break;
			}
			break;
		case 110: 
			switch (roll) {
			case 1:
				g = 80;
				getWealth((int) 'B');
				break;
			case 2:
				g = 90;
				getWealth((int) 'C');
				break;
			case 3:
				g = 100;
				getWealth((int) 'B');
				break;
			case 4:
				g = 110;
				getWealth((int) 'A');
				break;
			case 5:
				g = 130;
				getWealth((int) 'C');
				break;
			default: // 6
				g = 150;
				getWealth((int) 'A');
				break;
			}
			break;
		case ((int) 'A'):
			break;
		case ((int) 'B'):
			break;
		case ((int) 'C'):
			break;
		}
		return g;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void addInventoryBag(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void becomesDead(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	private void applyEquipmentPercentModsToPlayerAttributes(final BPCharacter player) {
		// TODO Auto-generated method stub
	}
	private void applyEquipmentPercentModsToPlayerSkills(final BPCharacter player) {
		// TODO Auto-generated method stub
	}
	private void applyEquipmentModsToPlayerAttributes(final BPCharacter player) {
		// TODO Auto-generated method stub
	}
	private void applyEquipmentModsToPlayerSkills(final BPCharacter player) {
		// TODO Auto-generated method stub

		/* example of modifiers is below:
		player.setMod_Attribute_Strength(Equipment.getInstance()
				.ARX_EQUIPMENT_Apply(player, io,
						GlobalConsts.IO_EQUIPITEM_ELEMENT_STRENGTH,
						player.getAttribute_Strength()));
		player.setMod_Attribute_Dexterity(Equipment.getInstance()
				.ARX_EQUIPMENT_Apply(player, io,
						GlobalConsts.IO_EQUIPITEM_ELEMENT_DEXTERITY,
						player.getAttribute_Dexterity()));
		player.setMod_Attribute_Constitution(Equipment.getInstance()
				.ARX_EQUIPMENT_Apply(player, io,
						GlobalConsts.IO_EQUIPITEM_ELEMENT_CONSTITUTION,
						player.getAttribute_Constitution()));
		player.setMod_Attribute_Mind(Equipment.getInstance()
				.ARX_EQUIPMENT_Apply(player, io,
						GlobalConsts.IO_EQUIPITEM_ELEMENT_MIND,
						player.getAttribute_Mind()));
		player.setMod_armor_class(Equipment.getInstance()
				.ARX_EQUIPMENT_Apply(player, io,
						GlobalConsts.IO_EQUIPITEM_ELEMENT_Armor_Class,
						player.getArmor_class()));
						*/
	}
	private void applySpellModsToPlayer(final BPCharacter player) {
		// TODO Auto-generated method stub

		/* example of modifiers is below:
		// the player is always Interactive Object 0
		io = Interactive.getInstance().getInteractiveObject(0);
		if (io != null) {
			for (short i = 0; i < io.getNb_spells_on(); i++) {
				int n = io.getSpells_onItem(i);
				SpellObject spell = Spell.getInstance().getSpell(n);
				if (spell.exists()) {
					switch (spell.getType()) {
					case GlobalConsts.SPELL_ARMOR:
						player.adjustMod_armor_class(spell
									.getCaster_level());
						break;
					case GlobalConsts.SPELL_LOWER_ARMOR:
						player.adjustMod_armor_class(-spell
									.getCaster_level());
						break;
					case GlobalConsts.SPELL_CURSE:
						player.adjustMod_Attribute_Strength(-spell
									.getCaster_level());
						player.adjustMod_Attribute_Constitution(-spell
									.getCaster_level());
						player.adjustMod_Attribute_Dexterity(-spell
									.getCaster_level());
						player.adjustMod_Attribute_Mind(-spell
									.getCaster_level());
						break;
					case GlobalConsts.SPELL_BLESS:
						player.adjustMod_Attribute_Strength(spell
									.getCaster_level());
						player.adjustMod_Attribute_Dexterity(spell
									.getCaster_level());
						player.adjustMod_Attribute_Constitution(spell
									.getCaster_level());
						player.adjustMod_Attribute_Mind(spell
									.getCaster_level());
						break;
					}
				}
			}
		}
		*/
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void computePlayerFullStats(final BPCharacter player) {
		if (player != null) {
			computePlayerStats(player);
			// clear all modifiers to ability scores
			player.clearModAbilityScores();

			// identify all equipment before applying modifiers
			//Equipment.getInstance().ARX_EQUIPMENT_IdentifyAll();
			// set the weapon type
			// player.setFull_Weapon_Type(Equipment.getInstance()
					//.ARX_EQUIPMENT_GetPlayerWeaponType());

			// Check for Equipment Modificators to Attributes
			applyEquipmentModsToPlayerAttributes(player);
			// Check for Equipment Modificators to Skills
			applyEquipmentModsToPlayerSkills(player);

			// / PERCENTILE.....
			applyEquipmentPercentModsToPlayerAttributes(player);
			applyEquipmentPercentModsToPlayerSkills(player);

			// Check for Spell Modifications
			applySpellModsToPlayer(player);
			
			try {
				// set full attributes
				float val = player.getBaseAbilityScore(BPConsts.ABILITY_COMBAT) 
				+ player.getModAbilityScore(BPConsts.ABILITY_COMBAT);
				player.setFullAbilityScore(BPConsts.ABILITY_COMBAT, val);
				
				if (player.getFullAbilityScore(BPConsts.ABILITY_COMBAT) < 0) {
					player.setFullAbilityScore(BPConsts.ABILITY_COMBAT, 0);
				}
	
				player.setFullAbilityScore(BPConsts.ABILITY_ENDURANCE, 
						player.getBaseAbilityScore(BPConsts.ABILITY_ENDURANCE));
				
				val = player.getBaseAbilityScore(BPConsts.ABILITY_MAX_ENDURANCE)
				+ player.getModAbilityScore(BPConsts.ABILITY_MAX_ENDURANCE);
				player.setFullAbilityScore(BPConsts.ABILITY_MAX_ENDURANCE, val);
				
				player.setFullAbilityScore(BPConsts.ABILITY_ENDURANCE,
						Math.min(player.getBaseAbilityScore(BPConsts.ABILITY_ENDURANCE), 
								player.getFullAbilityScore(BPConsts.ABILITY_MAX_ENDURANCE)));
			} catch (Exception ex) {
				JOGLErrorHandler.getInstance().fatalError(ex);
			}
		}
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void computePlayerStats(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void forcePlayerLookAtIO(BaseInteractiveObject io) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void frameCheck(BPCharacter pc, float delay) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void frameUpdate(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void gameReset(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void initializePlayer(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageDeath(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void manageMovement(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public long getXPforLevel(int profession, int level) {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void levelUp(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void modifyXP(BPCharacter pc, long val) {
		// TODO Auto-generated method stub
		
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void poison(BPCharacter pc) {
		// TODO Auto-generated method stub
		
	}
}
